﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;


namespace Multivee.UI
{
    [Designer(typeof(ScreenEditViewProxy))]
    public partial class ScreenEditView : UserControl
    {
        public event Func<Image> ImageRequested;
        public event Action<ScreenEditView> Selected;

        public ScreenEditView(ScreenViewConfiguration configuration)
        {
            InitializeComponent();
            Configuration = configuration;

            if (configuration != null)
            {
                Text = configuration.Name;
                Mosaic = configuration.Thumbnail;
                Index = configuration.ScreenIndex;
            }
        }

        public Image Mosaic
        {
            get
            {
                return pictureBox.Image;
            }

            set
            {
                if (value == null)
                    return;

                pictureBox.Image = value;
                pictureBox.BackgroundImage = null;
            }
        }

        public int Index
        {
            get;
            set;
        }

        [Browsable(true)]
        public override string Text
        {
            get
            {
                return Configuration.Name;
            }
            set
            {
                Configuration.Name = labelName.Text = value;
            }
        }

        public ScreenViewConfiguration Configuration
        {
            get;
            set;
        }

        private void pictureBox_DoubleClick(object sender, EventArgs e)
        {
            Image image =ImageRequested.Invoke();
            
            if (image != null)
                Mosaic = image;
        }

        private void ScreenEditView_MouseDown(object sender, MouseEventArgs e)
        {
            Selected.Invoke(this);
        }
    }
}
